<script setup lang="ts">
import type { FormRules } from 'element-plus';
import { reactive } from 'vue'
const formData = reactive({
  username: '',
  password: '',
})
const formDataRules: FormRules<typeof formData> = {
  username: [
    //非空校验 
    {
      required: true,
      message: '用户不能为空',
      trigger: 'blur'
    },
    // 正则校验
    {
      pattern: /^[a-zA-Z0-9_]{4,16}$/,
      message: '用户名格式不正确',
      trigger: 'blur'
    }
  ],
  password: [{
    required: true,
    message: '密码不能为空',
    trigger: 'blur'
  }, {
    pattern: /^[a-zA-Z0-9_]{4,16}$/,
    message: '密码格式不正确',
    trigger: 'blur'
  }]

}
</script>

<template>
  <el-form :model="formData" :rules="formDataRules">
    <el-form-item label="用户名">
      <el-input v-model="formData.username" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="formData.password" type="password" placeholder="请输入密码"></el-input>
    </el-form-item>
  </el-form>
</template>
<style></style>